var loginCtrl  = new XFApp.client();
XFApp.client.prototype.login = {
		successCode : 10000,
		urlItems : {			
			loginURL: basePath+"/login/login",			
		},
		
		formValidate : function(){
			$("#loginForm").validate({
				errorPlacement : function(error, element) {
					if (element.is(":radio"))
						error.appendTo(element.parent());
					else if (element.is(":checkbox"))
						error.appendTo(element.parent().parent());
					else if(element.is(":input"))
						error.appendTo(element.parent());
					else
						error.insertAfter(element); 
						//error.appendTo(element.parent().next());
				},
		        rules: {
		        	userId:   "required",
		        	password: "required"
				  },
				 messages: {
					 userId:   "请输入用户名",					           
			         password: "请输入密码"
				  }
		    });
			$("#loginForm").validate();
		},
		
		event : function (){			
			_this = this;
			
			$("#loginBtn").on("click",function(){				
				if($("#loginForm").validate().form()){
					loginCtrl.login.submit();					
				}				
			});
			//表单验证
			_this.formValidate();			
		},	
		
		
		submit : function (){
			
				var entity = {
			        userId : $("#userId").val(),
					password : $("#password").val(),
					//激活状态：1 已激活  审批状态：1审批通过
					//activeState:"1",
					//auditState:"1"
				}
		    	
		    	$.ajax({
		    		url :_this.urlItems.loginURL,
		    		data : entity,
		    		dataType : "json",
		    		type : 'post',
		    		success : function(data) {				
		    			if(data.code==_this.successCode
		    					|| data.code == 40120
		    					|| data.code == 40121){ 
		    				window.location.href= basePath;
		    			}else{
		    				window.webDialogUtil.alert("提示",data.msg);
		    			}
		    		}
		    	});	
			
		},
},

$(function(){	
	loginCtrl.login.event();
	
});